﻿using System;
using System.Collections.Generic;
using System.IO;


namespace DailyFx.Book.Repo
{

	public class TableImpl : ITable
	{
		enum Format
		{
			Excel	,
 			Tab		,
		}

		/// <summary>
		///		the parent book holds this table .
		/// </summary>
		private BookImpl _book;

	
		/// <summary>
		///		Contains the metrics for the data table .
		/// </summary>
		private Metrics _metrics;

		/// <summary>
		///		Contains the actual schema for columns .
		/// </summary>
		// private Schema _schema2 ;

		

		/// <summary>
		///		the data router for this table .
		/// </summary>
		// private Router _router;

		/// <summary>
		///		
		/// </summary>
		public readonly object _syncLock = new object();


		/// <summary>
		///		c'tor .
		/// </summary>
		public TableImpl ( BookImpl book, Metrics metrics )
		{
			this._book = book;
			this._metrics = metrics;

			// this._router = new Router( this) ;
		}

		/// <summary>
		///		Gets the book which owns this table .
		/// </summary>
		public IBook Book
		{
			get { return this._book; }
		}

		/// <summary>
		///		Gets the label of this table .
		/// </summary>
		public string Label
		{
			get { return this._metrics.Table; }
		}


		/// <summary>
		///		Gets the header of this table
		/// </summary>
		public Metrics Metrics
		{
			get { return this._metrics; }
		}

		
		/// <summary>
		///		Gets the declared schema  of wellknown fields for analysis .
		/// </summary>
		public Schema Schema
		{
			get { return this._metrics.Schema; }
		}

		/// <summary>
		///		Gets the symbol for this table .
		/// </summary>
		public Symbol Symbol
		{
			get { return this._metrics.Symbol; }
		}

		/// <summary>
		/// 
		/// </summary>
		public IRow getRow ( DateTime key )
		{
			return null ;
		}

		/// <summary>
		/// 
		/// </summary>
		public void setRow ( IRow row )
		{
			//using ( var readerImpl = new StreamReader( path) )
			//using (var reader = new CsvReader( readerImpl ))
			//{
			//	// Dictionary<string, string > reader.ReadComments ();
			//	this._header = reader.ReadHeader();
				 
			//	while ( reader.HasMoreRecords() )
			//	{
			//		var record = reader.ReadRow ();
			//		this._records.Add( record );
			//	}
			//}

			
			//return true;
		}

		/// <summary>
		/// 
		/// </summary>
		public void dropRow ( DateTime key )
		{
 			// todo :
		}

		public IRouter populateRouter ( DateTime start, DateTime end )
		{
			return null;
		}


		public void applyChanges()
		{
 
		}

		/// <summary>
		/// 
		/// </summary>
		public void Dispose()
		{ 
		}
		
	}
}
